package com.hymall.controller.wx;

import com.github.pagehelper.PageInfo;
import com.hymall.bean.MarketComment;
import com.hymall.bean.common.BasePageInfo;
import com.hymall.bean.common.BaseRespVo;
import com.hymall.bean.common.CommonData;
import com.hymall.bean.vo.WxCommentCountVO;
import com.hymall.service.wx.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @author 长平居士 - rolfcui@outlook.com
 * @description 评论模块
 * @date 2022/7/19 21:54
 */
@RestController
@RequestMapping("wx/comment")
public class WxCommentController {
    @Autowired
    CommentService commentService;

    @GetMapping("count")
    public BaseRespVo count(Integer valueId, Byte type) {
        System.out.println("valueId: " + valueId + " type: " + type);
        WxCommentCountVO vo = commentService.count(valueId, type);
        return BaseRespVo.ok(vo);
    }

    @GetMapping("list")
    public BaseRespVo list(Integer valueId, Byte type, BasePageInfo info, Integer showType) {
        // TODO 服务里面有点问题，暂时用 ASC 写死了
        // ? showType 是干嘛用的？
        CommonData<MarketComment> data = commentService.list(valueId, type, info, showType);
        return BaseRespVo.ok(data);
    }

    @PostMapping("post")
    public BaseRespVo post(@RequestBody MarketComment marketComment, Integer userId) {
        marketComment.setUserId(userId);
        marketComment.setAddTime(new Date());
        marketComment.setUpdateTime(new Date());
        commentService.post(marketComment);
        return BaseRespVo.ok();
    }

}
